﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}

<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>
<!DOCTYPE html>
<html>
@* <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.18/dist/css/layui.css" rel="stylesheet">
</head> *@
<body>

    <form class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-form-item">

                <div class="layui-inline">
                    <label class="layui-form-label">负责人</label>
                    <div class="layui-input-block">
                        <select id="responsible" lay-filter="testSelect">
                            <option value="">请选择</option>
                            <option value="张三">张三</option>
                            <option value="李四">李四</option>
                            <option value="王五">王五</option>
                        </select>
                    </div>
                    <label class="layui-form-label">妊检日期</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <input type="date" id="pregnancyTestDate" class="layui-input">
                    </div>



                    <button type="button" class="layui-btn layui-bg-red" onclick="Add()" lay-on="test-iframe-curl">新增</button>

                </div>


            </div>


            <table class="layui-table">
                <thead>
                    <tr>
                        <td>耳号</td>
                        <td>妊检结果</td>
                        <td>妊检方式</td>
                        <td>同胎数</td>
                        <td>妊检天数</td>
                        <td>当前栋舍</td>
                        <td>当前栏位</td>
                        <td>转入栋舍</td>
                        <td>转入栏位</td>

                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>
                            <select id="earBugles" lay-filter="testSelect">
                                <option value="">请选择</option>
                            </select>
                        </td>
                        <td> <input type="text" id="pregnancyTestResults" class="layui-input"></td>
                        <td>
                            <div class="layui-inline">
                                <select id="pregnancyTestWays" lay-filter="testSelect1">
                                    <option value="">请选择</option>
                                    <option value="公羊试精">公羊试精</option>
                                    <option value="人工检查">人工检查</option>
                                    <option value="B超检查">B超检查</option>
                                </select>
                            </div>
                        </td>
                        <td> <input type="text" id="numberParities" class="layui-input"></td>
                        <td> <input type="text" id="pregnancyDays" class="layui-input"></td>
                        <td> <input type="text" id="cottageName" class="layui-input"></td>
                        <td> <input type="text" id="fieldName" class="layui-input"></td>
                        <td>
                            <select id="cottageId" lay-filter="provincet">
                                <option value="">请选择</option>
                            </select>
                        </td>
                        <td>
                            <select id="field" lay-filter="city">
                                <option value="">请选择</option>
                            </select>
                        </td>
                    </tr>
                </tbody>
            </table>


            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" class="layui-textarea" id=""></textarea>
                </div>
            </div>
        </div>

    </form>


    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    <script src="//unpkg.com/layui@2.9.18/dist/layui.js"></script>
    <script>

        layui.use('form', function () {
            var table = layui.table;
            var form = layui.form;
            var layer = layui.layer;

            //绑定耳号
            bangsheng1();
            //绑定栋舍
            bangsheng();

            FantearBugles();



            //获取耳号下拉框的值
            form.on('select(testSelect)', function (data) {
                FantearBugles(data.value); // data.value 返回选中的值
                console.log(data.value, 6666666666)
            });


            //绑定栋舍
            function bangsheng() {
                $.ajax({
                    url: "http://localhost:5123/api/Cottage/CottageSecondaryQuery",
                    data: JSON.stringify({}),
                    type: "post",
                    async: false,
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        console.log(res)
                        $.each(res.data, function () {
                            $("#cottageId").append(`<option value="${this.cottageId}">${this.cottageName}</option>`);
                        })
                        form.render('select'); // 重新渲染下拉框
                    }
                })
            }

            //获取栋舍下拉框的值
            form.on('select(provincet)', function (data) {
                provincetId1 = data.value;
                console.log(provincetId1, 15152)
                $("#field").empty();
                $("#field").append('<option value="">请选择</option>');
                bangshi()

            });

            //绑定栏位
            function bangshi() {
                var cottageId = $("#cottageId").val();
                $.ajax({
                    url: "http://localhost:5123/api/Field/GetFieldCottage",
                    data: JSON.stringify({ cottageId: cottageId }),
                    type: "post",
                    async: false,
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        console.log(res.data)

                        $.each(res.data, function () {
                            $("#field").append(`<option value="${this.fieldId}">${this.fieldName}</option>`);
                        })
                        form.render('select'); // 重新渲染下拉框
                    }

                })
            }

            //绑定耳号
            function bangsheng1() {

                $.ajax({
                    url: "http://localhost:5269/api/SheepArchive/SheepEarBuglesQuery",
                    data: JSON.stringify({}),
                    type: "post",
                    async: false,
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        console.log(res)
                        $.each(res.data, function () {
                            $("#earBugles").append(`<option value="${this.recordAuricle}">${this.recordAuricle}</option>`);
                        })
                        form.render('select'); // 重新渲染下拉框

                    }

                })
            }

            //根据耳号加载数据
            function FantearBugles(aa) {
                //var recordAuricle = $("#earBugles").val();
                $.ajax({
                    url: 'http://localhost:5269/api/SheepArchive/SheepEarBuglesBackFill',
                    type: 'post',
                    data: JSON.stringify({ recordAuricle: aa }),
                    dataType: 'json',
                    contentType: 'application/json',
                    success: res => {
                        $(res.data).each(function () {
                            $("#cottageName").val(this.cottageName)
                            $("#fieldName").val(this.fieldName)
                        })
                        console.log(res, 88888)
                    }
                })
            }

        })



        //种母妊检
        function Add() {
            var data = {
                // 耳号
                earBugles: $("#earBugles").val(),
                //妊检日期
                pregnancyTestDate:$("#pregnancyTestDate").val(),
                //负责人
                responsible: $("#responsible").val(),
                //妊检结果
                pregnancyTestResults: $("#pregnancyTestResults").val(),
                //妊检方式
                pregnancyTestWays: $("#pregnancyTestWays").val(),
                //同胎数
                numberParities: $("#numberParities").val(),
                //妊检天数
                pregnancyDays: $("#pregnancyDays").val(),
                //当前栋舍
                currentBuildings: $("#cottageName").val(),
                //当前栏位
                currentColumns: $("#fieldName").val(),
                //转入栋舍
                cottageId: $("#cottageId").val(),
                //转入栏位
                fieldId: $("#field").val()
            }

            $.ajax({
                url: "http://localhost:5269/api/SheepArchive/PregnancyTestCreate",
                type: 'post',
                data: JSON.stringify(data),
                dataType: "json",
                contentType: "application/json",
                success: res => {
                    if (res.code == 0) {
                        layer.msg('添加成功')
                        location.href = "/Birth/PregnancyTest/"
                    }
                    else {
                        layer.msg('保存失败')
                    }
                }
            })
        }



    </script>


</body>

</html>